//
//  BaseView.m
//  Zaker
//
//  Created by 赵磊 on 16/3/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BaseView.h"

@implementation BaseView

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self creatNight];
}

- (void)creatNight
{
    //监听中心,监听后面发来的信息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"change" object:nil];
    
    //从night中取出储存的字符串(yes,no)
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"night"];
    
    if ([passWord isEqualToString:@"yes"]) {
        self.backgroundColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
    } else {
        self.backgroundColor = [UIColor whiteColor];
    }
}

#pragma mark - defaultCenter方法
- (void)changeColor:(NSNotification *)center
{
    /*改变背景*/
    self.backgroundColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
    
    //找到字符串
    NSString *passWord = [center object];
    
    //消息中心发出消息NSUserDefaults将object中的字符串存入night中
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:passWord forKey:@"night"];
    
    //判断是yes还是no,yes的话改变背景颜色
    if ([passWord isEqualToString:@"no"]) {
        self.backgroundColor = [UIColor whiteColor];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
